package com.oa.ylms.apps.actions.plan;

import java.util.List;

import com.oa.ylms.apps.actions.BasicAction;
import com.oa.ylms.apps.business.plan.IMessageInfoService;
import com.oa.ylms.apps.constants.message.IMessageInfoStates;
import com.oa.ylms.apps.entity.archives.StaffInfoValue;
import com.oa.ylms.apps.entity.plan.MessageInfoValue;

@SuppressWarnings("serial")
public class MessageInfoAction extends BasicAction {

	private IMessageInfoService service;
	private int states = IMessageInfoStates.UNDEFINED;
	private List<MessageInfoValue> list;
	private int unreadCount;
	private int totalCount;
	private int messageId;
	private String messageIds;

	public String query() throws Exception {
		staffInfo = (StaffInfoValue) session.get("login_staffInfo");
		int staffId = staffInfo.getStaffId();
			totalpage = service.countTPage(staffId, states, rows);
			count = service.getTotalNumber();
			if (count % rows == 0 && totalpage + 1 == currpage) {
				currpage = currpage - 1;
				totalpage = currpage;
			}
			list = service.queryMessageInfoWithPage(staffId,
					states, rows, currpage);
		return "show";
	}

	public String delete() {

		return "delete";

	}

	public String deleteMore() {
		String[] arrayStr = messageIds.split(",");
		for(int i =0;i<arrayStr.length;i++){
			int messageId = Integer.parseInt(arrayStr[i]);
			try {
				service.deleteMessageInfo(messageId);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "delete";
	}

	public String read() {
		try {
			service.read(messageId);
			response.setContentType("text/html; charset=gb2312");
			response.setHeader("Cache-Control", "no-cache");
			response.getWriter().write("ok");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public String getTotalMessageCount(){
		staffInfo = (StaffInfoValue) session.get("login_staffInfo");
		try {
			service.getTotalCount(staffInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "totalCount";
	}
	
	public String getUnreadMessageCount(){
		staffInfo = (StaffInfoValue) session.get("login_staffInfo");
		try {
			service.getUnreadCount(staffInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "unreadCount";
	}

	public IMessageInfoService getService() {
		return service;
	}

	public void setService(IMessageInfoService service) {
		this.service = service;
	}

	public int getStates() {
		return states;
	}

	public void setStates(int states) {
		this.states = states;
	}

	public List<MessageInfoValue> getList() {
		return list;
	}

	public void setList(List<MessageInfoValue> list) {
		this.list = list;
	}

	public int getUnreadCount() {
		return unreadCount;
	}

	public void setUnreadCount(int unreadCount) {
		this.unreadCount = unreadCount;
	}

	public int getMessageId() {
		return messageId;
	}

	public void setMessageId(int messageId) {
		this.messageId = messageId;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public String getMessageIds() {
		return messageIds;
	}

	public void setMessageIds(String messageIds) {
		this.messageIds = messageIds;
	}

}
